package com.itheima.api.stream.demo03;

import java.util.ArrayList;
import java.util.stream.Stream;

public class StreamMiddleOperate {

    public static void main(String[] args) {

        ArrayList<Integer> list = new ArrayList<>();
        list.add(8);
        list.add(2);
        list.add(1);
        list.add(3);
        list.add(4);
        list.add(7);
        list.add(9);
        list.add(0);
        list.add(5);
        list.add(6);

        list.stream().filter(s -> {
            if (s > 5){
                return true;
            } else {
                return false;
            }
        }).forEach(s -> System.out.println(s));
        System.out.println("--------filter---------");

        list.stream().limit(3).forEach(s -> System.out.println(s));
        System.out.println("---------limit--------");

        list.stream().skip(3).forEach(s -> System.out.println(s));
        System.out.println("---------skip-------------");

        ArrayList<Integer> list1 = new ArrayList<>();
        list1.add(11);
        list1.add(13);
        list1.add(12);
        list1.add(4);
        Stream<Integer> stream = Stream.concat(list.stream(), list1.stream());
//        stream.forEach(s -> System.out.println(s));
        System.out.println("------------contact-----------------");

//        stream.distinct().forEach(s -> System.out.println(s));
        System.out.println("--------------distinct--------------");

//        stream.sorted().forEach(s -> System.out.println(s));
        System.out.println("--------------sorted()--------------");

        stream.sorted((o1, o2) -> o1 - o2).forEach(s -> System.out.println(s));
        System.out.println("---------------sorted(Comparator comparator)-----------------");



    }
}
